﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Tasx.Definitions;

namespace Tasx.ViewModels
{
    public class MainViewModel : ViewModelBase
    {
        private readonly ITaskProvider _provider;

        public MainViewModel(ITaskProvider provider)
        {
            _provider = provider;
        }

        public ICommand Sync
        {
            get { return new RelayCommand<object>(p => ExecuteSync(), p => CanExecuteSync()); }
        }
        private void ExecuteSync()
        {
            var proxy = _provider.Sync(null);
            MessengerInstance.Send(new SyncedMessage(proxy));
        }
        private bool CanExecuteSync()
        {
            return true;
        }
    }

    public class SyncedMessage
    {
        public SyncedMessage(TasksProxy proxy)
        {
            Proxy = proxy;   
        }

        public TasksProxy Proxy { get; private set; }
    }
}
